package com.wgh.product.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;

/**
 * 统一响应结果类
 * @param <T>
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    private int code;
    private String message;
    private T data;
    
    /**
     * 成功响应
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }
    
    /**
     * 成功响应，无数据
     */
    public static <T> Result<T> success() {
        return new Result<>(200, "成功", null);
    }
    
    /**
     * 失败响应
     */
    public static <T> Result<T> error(String message) {
        return new Result<>(500, message, null);
    }
    
    /**
     * 失败响应，自定义错误码
     */
    public static <T> Result<T> error(int code, String message) {
        return new Result<>(code, message, null);
    }
}